package com.eostoken.eos_wallet.mvp.presenter;

import android.app.Activity;
import android.content.Context;

import com.eostoken.eos_wallet.eosnet.callback.CheckDataTaskCallback;
import com.eostoken.eos_wallet.mvp.callback.CommonCallback;
import com.eostoken.eos_wallet.mvp.mode.AppsModel;
import com.eostoken.eos_wallet.mvp.view.AppsView;
import com.fredy.mvp.BasePresenter;

import java.util.Map;

import static com.eostoken.eos_wallet.utils.Constants.ADD_ORDER;
import static com.eostoken.eos_wallet.utils.Constants.BIND_ADDRESS;
import static com.eostoken.eos_wallet.utils.Constants.BIND_MID;
import static com.eostoken.eos_wallet.utils.Constants.CHECK_ADDR;
import static com.eostoken.eos_wallet.utils.Constants.FIND_MID;
import static com.eostoken.eos_wallet.utils.Constants.GET_BIND_ADDRESS;
import static com.eostoken.eos_wallet.utils.Constants.INDEX_MARK;
import static com.eostoken.eos_wallet.utils.Constants.IS_FIND_MID;
import static com.eostoken.eos_wallet.utils.Constants.MORTGAGE;
import static com.eostoken.eos_wallet.utils.Constants.MY_MGP_ORDER;
import static com.eostoken.eos_wallet.utils.Constants.MY_ORDER;
import static com.eostoken.eos_wallet.utils.Constants.NODE_INDEX;
import static com.eostoken.eos_wallet.utils.Constants.ORDER_INDEX;
import static com.eostoken.eos_wallet.utils.Constants.PRICE;
import static com.eostoken.eos_wallet.utils.Constants.TEALTIME_INDEX;
import static com.eostoken.eos_wallet.utils.Constants.WITHD_RAW_INDEX;

public class AppsPresenterImpl extends BasePresenter<AppsModel, AppsView> implements AppsPresenter, CommonCallback, CheckDataTaskCallback {

    private Activity context;

    public AppsPresenterImpl(Activity context) {
        super(context);
        this.context = context;
    }

    @Override
    public void onSuccess(Object data, String successMsg, int responseSuccessCode) {
        try {
            if (getView() != null)
                getView().updateView(data, responseSuccessCode);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void onFailure(String msg, int responseFailCode) {
        try {
            if (getView() != null)
                getView().onFailure(msg, responseFailCode);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void update(Object object) {

    }

    @Override
    public void finish(boolean success, Object o1, Object o2) {
        try {
            if (getView() != null)
                getView().updateView(success, o1, o2);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    @Override
    public void sendTransaction(String action, String privateKey, String fromAccount, String code, String jsonData) {
        model.transaction(action, privateKey, fromAccount, code, jsonData, this);
    }

    @Override
    public void requestTableRows(Map<String, Object> map) {
        model.getTableRows(context, map, true, this);
    }

    @Override
    public void requestCurrencyBalance(Map<String, Object> map) {
        model.getCurrencyBalance(context, map, true, this);
    }

    @Override
    public void requestPortData(String params, int type) {
        switch (type) {
            case PRICE:
                model.getDIGICCYPrice(context, params, type, true, this);
                break;
            case FIND_MID:
                model.getFindMgp(context, params, type, true, this);
                break;
            case ORDER_INDEX:
                model.getOrderIndex(context, params, type, true, this);
                break;
            case TEALTIME_INDEX:
                model.getRealTimeIndex(context, params, type, true, this);
                break;
            case MORTGAGE:
                model.getMortgageAssociation(context, params, type, true, this);
                break;
            case BIND_MID:
                model.getBindMidMgp(context, params, type, true, this);
                break;
            case NODE_INDEX:
                model.getNodeIndex(context, params, type, true, this);
                break;
            case MY_ORDER:
                model.getMyOrderWallet(context, params, type, true, this);
                break;
            case WITHD_RAW_INDEX:
                model.getWithdrawIndex(context, params, type, true, this);
                break;
            case ADD_ORDER:
                model.getWithdrawAddOrder(context, params, type, true, this);
                break;
            case INDEX_MARK:
                model.getIndexMarkIndex(context, params, type, true, this);
                break;
            case GET_BIND_ADDRESS:
                model.getBindWalletAddress(context, params, type, true, this);
                break;
            case BIND_ADDRESS:
                model.bindWalletAddress(context, params, type, true, this);
                break;
            case CHECK_ADDR:
                model.checkAddr(context, params, type, true, this);
                break;
            case IS_FIND_MID:
                model.isFindMIDBinding(context, params, type, true, this);
                break;
            case MY_MGP_ORDER:
                model.getMiningOrderIncome(context, params, type, true, this);
                break;
        }
    }

    @Override
    protected void onViewDestroy() {

    }

    @Override
    public void getData(boolean isRefresh) {

    }

    @Override
    public void getMoreData() {

    }
}
